package com.shundr.shipper.common.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.QueryBuilder;
import com.shundr.shipper.common.model.HistoryAreaInfo;
import com.shundr.shipper.frame.db.LDaoManager;
import com.shundr.shipper.frame.util.LLogger;
/**
 * 
 * HistoryAreaDao
 * 
 * @author larry 2015-7-17 上午9:24:48 
 * @version 1.0.0
 *
 */
public class HistoryAreaDao {
	
	private Dao<HistoryAreaInfo, Integer> areaDao;
	
	public HistoryAreaDao() {
		areaDao = LDaoManager.createDao(HistoryAreaInfo.class);
	}
	
	/**
	 * 获取所有的区域
	 * getHistoryAreas(这里用一句话描述这个方法的作用)
	 * (这里描述这个方法适用条件 – 可选)
	 * @return
	 * List<HistoryAreaInfo>
	 * @exception
	 * @since  1.0.0
	 */
	public List<HistoryAreaInfo> getHistoryAreas(){
		try {
			QueryBuilder<HistoryAreaInfo, Integer> queryBuilder = areaDao.queryBuilder();
			queryBuilder.orderBy("time", false);
			queryBuilder.limit(8);
			return queryBuilder.query();
		} catch (SQLException e) {
			LLogger.e("创建数据类型时异常" + e);
		}
		return new ArrayList<HistoryAreaInfo>();
	}
	
	/**
	 * 插入数据
	 * insert(这里用一句话描述这个方法的作用)
	 * (这里描述这个方法适用条件 – 可选)
	 * @param info
	 * void
	 * @exception
	 * @since  1.0.0
	 */
	public void insert(HistoryAreaInfo info){
		try {
			if(areaDao.update(info) == 0){
				areaDao.create(info);
			}
		} catch (SQLException e) {
			LLogger.e("创建数据类型时异常" + e);
		}
	}
	
}
